package com.javaweb.vo;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class CommentVO {
    private String candidateName ;
    private String userName ;
    private String comment ;
    @JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
    private Date commTime ;


    public String getCandidateName() {
        return candidateName;
    }

    public void setCandidateName(String candidateName) {
        this.candidateName = candidateName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Date getCommTime() {
        return commTime;
    }

    public void setCommTime(Date commTime) {
        this.commTime = commTime;
    }

    public static CommentVO build(Map<String, Object>requestData) {
        CommentVO commentVO = new CommentVO() ;
        commentVO.setCandidateName((String) requestData.get("candidateName"));
        commentVO.setUserName((String) requestData.get("userName"));
        commentVO.setComment((String) requestData.get("comment"));
        commentVO.setCommTime(new Date()) ;
        return commentVO ;

    }

    public static List<CommentVO> generateComments() {
        List<CommentVO> commentVOList = new ArrayList<>() ;
        CommentVO comment = null ;
        for (int i=0; i<10; i++) {
            comment = new CommentVO() ;
            comment.setCandidateName("候选人_" + i);
            comment.setUserName("投票人_" + i);
            comment.setComment("真是个很不错的好人，候选人，非常正直。好同志。");
            comment.setCommTime(new Date());
            commentVOList.add(comment) ;
        }
        return commentVOList ;
    }
}
